import java.util.ArrayList;
import java.util.List;

public class Calculator {

	public String divide(String a, String b, Integer... precision) {
		int aInt = Integer.parseInt(a);
		int bInt = Integer.parseInt(b);
		int p = (precision.length == 0) ? 5 : precision[0];
		if(bInt==0)throw new DivideByZeroException("You can't  divide by zero!");
		return encodeToString(countSubstraction(aInt, bInt, p));
		
	}

	List<Integer> countSubstraction(int a, int b, int precision) {
		ArrayList<Integer> ar = new ArrayList<>();
		int whole = 0;
		int rest = a;
		while ((rest != 0) && (precision != (ar.size() - 1))) {
			while (rest >= b) {
				rest = rest - b;
				whole++;
			}
			ar.add(whole);
			whole = 0;
			rest = rest * 10;
		}
		return ar;
	}

	String encodeToString(List<Integer> ar) {
		String s = "";
		for (int i = 0; i < ar.size(); i++) {
			s = s + ar.get(i);
			if (i == 0)
				s = s + ".";
		}
		return s;
	}

	public double add(String aString, String bString) {
		double a = Double.parseDouble(aString);
		double b = Double.parseDouble(bString);
		a = a + b;
		return a;
	}

	public double sub(String aString, String bString) {
		double a = Double.parseDouble(aString);
		double b = Double.parseDouble(bString);
		a = a - b;
		return a;
	}

	public double mult(String aString, String bString) {
		double a = Double.parseDouble(aString);
		double b = Double.parseDouble(bString);
		double pom = a;
		int count = 0;
		while (b - 1 != count) {
			count++;
			a = a + pom;

		}
		return a;
	}
}
